// const baseUrl = 'http://47.107.238.6:8081'
// const baseUrl ='http://192.168.1.5:8088'
// const baseUrl = 'http://192.168.0.199:8090'
// const baseUrl = 'http://192.168.3.5:8090'


import env from './env.js';

const baseUrl = env.baseUrl

export const request = (options) => {
	return new Promise((resolve, reject) => {
		let token = uni.getStorageSync('token')
		uni.request({
			url: baseUrl + options.url,
			method: options.method || 'GET',
			data: options.data || {},
			header: options.header || {
				Authorization: token,
			},
			success: (res) => {
				const data = res.data
				const userLoginInfo = uni.getStorageSync('token');
				if (!userLoginInfo) {
					uni.navigateTo({
						url: '/pages/logo/logo'
					})
				} else if (data.code !== 200) {
					// 
					
					
					console.log(data.code);
					uni.showToast({
						icon: 'error',
						title: '操作错误'
					})
				}
				resolve(data)
			},
			fail: (error) => {
				uni.showToast({
					icon: 'error',
					title: '系统错误'
				})
				uni.navigateTo({
					url: '/pages/logo/logo'
				})
				reject(error)
			}
		})
	})
}